//
//  JKPurchaseView.m
//  JackToolsBox
//
//  Created by Blue on 2020/1/19.
//  Copyright © 2020 Jack Xue. All rights reserved.
//

#import "JKPurchaseView.h"

@implementation JKPurchaseView
{
    UIButton *_buyBtn;
    UIButton *_restoreBtn;
    UIButton *_allRestoreBtn;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
        _buyBtn = [[UIButton alloc] initWithFrame:CGRectZero];
        [_buyBtn setTitle:@"购买" forState:UIControlStateNormal];
        [_buyBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self addSubview:_buyBtn];
        
        _restoreBtn = [[UIButton alloc] initWithFrame:CGRectZero];
        [_restoreBtn setTitle:@"恢复购买" forState:UIControlStateNormal];
        [_restoreBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self addSubview:_restoreBtn];
        
        _allRestoreBtn = [[UIButton alloc] initWithFrame:CGRectZero];
        [_allRestoreBtn setTitle:@"获取所有恢复购买项" forState:UIControlStateNormal];
        [_allRestoreBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self addSubview:_allRestoreBtn];
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _buyBtn.frame = CGRectMake(100, 100, 100, 44);
    
    _restoreBtn.frame = CGRectMake(100, 180, 100, 44);
    
    _allRestoreBtn.frame = CGRectMake(100, 280, 160, 44);
}

- (void)setDelegate:(id)delegate
{
    _delegate = delegate;
    [_buyBtn addTarget:delegate action:@selector(buy) forControlEvents:UIControlEventTouchUpInside];
    [_restoreBtn addTarget:delegate action:@selector(restorePurchase) forControlEvents:UIControlEventTouchUpInside];
    [_allRestoreBtn addTarget:delegate action:@selector(allRestoreProducts) forControlEvents:UIControlEventTouchUpInside];
}
@end
